<template>
  <div class="class-check-detail">
    <h3 class="title">开班检查详情</h3>
    <div>
      <p-table
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataList"
        :pagination="false"
        :rowClassName="record => record.judgeStatus == '1' ? 'mark-font' : ''"
      >
        <template
          v-if="isShowAction"
          slot="action"
          slot-scope="text, record"
        >
          <p-button type="link">消息推送</p-button>
        </template>
      </p-table>
    </div>
  </div>
</template>

<script>
import { initDictOptions, filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import _find from 'lodash/find'
export default {
  prop: {
    isShowAction: {
      type: Boolean,
      default: false
    },
    dictOptions: {
      type: Array,
      default: () => null
    }
  },
  data () {
    return {
      dataList: [],
      dictOptions: {},
      cols: [
        {
          title: '序号', key: 'rowIndex', width: 60, align: 'center',
          customRender (t, r, index) {
            return parseInt(index) + 1
          },
        },
        { title: '检验项目', dataIndex: 'testItemName', align: 'center' },
        {
          title: '检验方式', dataIndex: 'testMethod', align: 'center',
          customRender: (text) => {
            if (!text.toString()) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['method'], text + '')
            }
          },
        },
        {
          title: '检验结果', dataIndex: 'testResult', align: 'center',
          customRender (t, r, index) {
            return t == '0' ? '合格' : '不合格'
          }
        },
        {
          title: '检验判定', dataIndex: 'judgeStatus', align: 'center',
          customRender (t, r, index) {
            return t == '0' ? '合格' : '不合格'
          }
        },
        { title: '操作', dataIndex: 'action', align: 'center', scopedSlots: { customRender: 'action' } },
      ]
    }
  },
  computed: {
    columns () {
      return !this.isShowAction ? this.cols.filter(v => v.title != '操作') : this.cols
    }
  },
  mounted () {
    this.getDicOptions()
  },
  methods: {
    getDicOptions () {
      initDictOptions('mes_checkitemno', null).then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'method', res.data)
        }
      })
    },
  }
}
</script>

<style scoped lang="less">
.class-check-detail {
  .title {
    font-size: 14px;
    line-height: 22px;
    padding-left: 13px;
    margin: 10px 0;
    border-left: 4px solid rgb(64, 100, 223);
  }
}
/deep/.poros-table-bordered.poros-table-fixed-header
  .poros-table-scroll
  .poros-table-header.poros-table-hide-scrollbar
  .poros-table-thead
  > tr:only-child
  > th:last-child {
  border-right-color: 1px solid rgb(236, 237, 240);
}
/deep/.mark-font td {
  color: red;
}
</style>
